#include "gui/layers/RouteLayer.h"
#include "gui/objects/GUIRoute.h"
#include "util/events/Event.h"

namespace gui {

class RouteChangeEventListener : public EventListener {
public:
	RouteChangeEventListener(RouteLayer* routeLayer): EventListener(RouteChanged_Event) { this->routeLayer = routeLayer; }
	~RouteChangeEventListener() {}
	void execute(Event* event) { this->routeLayer->update(); }
private:
	RouteLayer* routeLayer;
};

RouteLayer::RouteLayer(SurfaceFactory* surfaceFactory, RouteController* routeController) : DynamicLayer(surfaceFactory), drawer(surfaceFactory) {
	this->routeController = routeController;
	this->routeController->addEventListener(new RouteChangeEventListener(this));
	GUIRoute guiRoute(&this->drawer, this->routeController);
	this->updateSurface(guiRoute);
}

RouteLayer::~RouteLayer() {

}

void RouteLayer::update() {
	GUIRoute guiRoute(&this->drawer, this->routeController);
	this->updateSurface(guiRoute);
}

}
